class ElementUtils {
  static getElementProps<T extends keyof HTMLElement>(
    selector: string,
    props: T[]
  ): MyRecord<T, string> {
    const ele = document.querySelector(selector) as HTMLElement;
    return props.reduce((acc, prop) => {
      return {
        ...acc,
        [prop]: ele[prop],
      };
    }, {} as MyRecord<T, string>);
  }

  static getElementBottomCenterAxis(selector: string) {
    const ele = document.getElementById(selector);
    if (ele) {
      const rect = ele.getBoundingClientRect();
      const scrollTop =
        window.pageYOffset || document.documentElement.scrollTop;
      const middleBottomX = rect.left + rect.width / 2;
      const middleBottomY = rect.top + rect.height / 2 + scrollTop;
      return {
        x: middleBottomX,
        y: middleBottomY,
      };
    }
  }

  static getElementHalfWidth(selector: string) {
    const ele = document.querySelector(selector);
    if (ele) {
      // 获取元素的边界矩形（包括边框、滚动条、边距等）
      const rect = ele.getBoundingClientRect();

      // 计算元素宽度的一半
      const halfWidth = rect.width / 2;

      // 返回宽度的一半
      return halfWidth;
    }
  }
}

const elementUtils = new ElementUtils();
export { elementUtils, ElementUtils };
